package org.eliza.rpc.rpc

import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.rpc.krpc.ktor.server.Krpc
import kotlinx.rpc.krpc.ktor.server.rpc
import kotlinx.rpc.krpc.serialization.json.json
import org.eliza.rpc.rpc.model.AwesomeParameters
import org.eliza.rpc.rpc.model.AwesomeService
import org.eliza.rpc.rpc.model.AwesomeServiceImpl

fun main() {
    embeddedServer(Netty,8080) {
        install(Krpc)
        routing {
            get {
                call.respondText("Hello World!")
            }
            rpc("/awesome") {
                rpcConfig {
                    serialization {
                        json()
                    }
                }
                registerService<AwesomeService> { ctx ->
                    AwesomeServiceImpl(AwesomeParameters(false, null), ctx)
                }
            }
        }
    }.start(wait = true)
}